//
//  NSMutableAttributedString+TP_Utility.m
//  E_Car
//
//  Created by 谭鹏 on 2017/4/14.
//  Copyright © 2017年 谭鹏. All rights reserved.
//

//#import "NSMutableAttributedString+TP_Utility.h"
#import <UIKit/UIKit.h>
//#import "TPUIMacro.h"
@implementation NSMutableAttributedString (TP_Utility)
+(NSMutableAttributedString *) attributedStringWithContent:(NSString *)content leftRightIndent:(CGFloat)indent {
    
    NSMutableAttributedString * text = [[NSMutableAttributedString alloc]initWithString:NSLocalizedString(content, nil)];
    NSMutableParagraphStyle * style = [[NSMutableParagraphStyle alloc]init];
    
    
    
    //    style.lineSpacing = lineSpacing ;
    //    if (headIndent > 0) {
    //        style.firstLineHeadIndent = firstLineHeadIndent;
    //    }
    //    else{
    //        style.alignment = alignment;
    //    }
    
    //    style.paragraphSpacing = PX(5);
    style.firstLineHeadIndent = indent;
    style.headIndent = indent;
    style.tailIndent = [UIScreen mainScreen].bounds.size.width - indent;
    //    style.paragraphSpacingBefore = 20;
    //    style.paragraphSpacing = 20;
    //----attri
    [text addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
    
    return text;
}
+ (NSMutableAttributedString *)attributedStringWithStr1:(NSString *) str1 color1:(UIColor *)color1 font1:(UIFont *)font1 Str2:(NSString *) str2 color2:(UIColor *)color2 font2:(UIFont *)font2{

    if (!font2) {
        font2 = font1.copy;
    }
    if (!color2) {
        color2 = color1.copy;
    }
//    [attrStr addAttribute:NSFontAttributeName value:font1 range:range1];
//    [attrStr addAttribute:NSFontAttributeName value:font2 range:range2]; //第一个 attr 会失效
//    
//    [attrStr addAttribute:NSForegroundColorAttributeName value:color1 range:range1];
//    [attrStr addAttribute:NSForegroundColorAttributeName value:color2 range:range2]; //第一个 attr 会失效
    NSMutableAttributedString * attrStr = [NSMutableAttributedString new];
    NSDictionary *dictAttr1 = @{NSFontAttributeName:font1,NSForegroundColorAttributeName:color1};
    NSAttributedString *attr1 = [[NSAttributedString alloc]initWithString:str1 attributes:dictAttr1];
    [attrStr appendAttributedString:attr1];
    
    NSDictionary *dictAttr2 = @{NSFontAttributeName:font2,NSForegroundColorAttributeName:color2};
    NSAttributedString *attr2 = [[NSAttributedString alloc]initWithString:str2 attributes:dictAttr2];
    [attrStr appendAttributedString:attr2];
    
    return attrStr;
}
@end
